/**
 * @program MHAG
 * @ Charm Dialog Class
 * @version 1.0
 * @author Tifa@mh3
 *
 */
package org.mhag.swing;
import org.mhag.model.*;
/**
 *
 * @author lvmy
 */
public class GenAdvanced extends javax.swing.JDialog {

    /** Creates new form GenAdvanced */
    public GenAdvanced(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public GenAdvanced(java.awt.Frame parent, boolean modal, Generator aGen) {
        super(parent, modal);
        initComponents();
		gen = aGen;
	 	defaultMenuSelection();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        formulaPanel = new javax.swing.JPanel();
        formula1 = new javax.swing.JLabel();
        formula3 = new javax.swing.JLabel();
        formula2 = new javax.swing.JLabel();
        paraPanel = new javax.swing.JPanel();
        labelE1 = new javax.swing.JLabel();
        labelE2 = new javax.swing.JLabel();
        labelE3 = new javax.swing.JLabel();
        labelE4 = new javax.swing.JLabel();
        labelE5 = new javax.swing.JLabel();
        menuE1 = new javax.swing.JComboBox();
        menuE2 = new javax.swing.JComboBox();
        menuE3 = new javax.swing.JComboBox();
        menuE4 = new javax.swing.JComboBox();
        menuE5 = new javax.swing.JComboBox();
        optionPanel = new javax.swing.JPanel();
        methodMenu = new javax.swing.JComboBox();
        methodMenuLabel = new javax.swing.JLabel();
        numberMenuLabel = new javax.swing.JLabel();
        numberMenu = new javax.swing.JComboBox();
        defaultButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Advanced Settings (Reset to default when MHAG exits) ");
        setResizable(false);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
                formWindowLostFocus(evt);
            }
        });

        formulaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Formula"));

        formula1.setText("<html><b>Score</b>  =  \"defense\" /<b> E1</b>  - \"# of  negative skills\" x <b>E2</b> </html>");

        formula3.setText("<html>+ sum of \"query skills\" ( (<b>E3</b> + \"trigger points\") or \"skill points\")</html>");

        formula2.setText("<html>+ \"# of unused slots\" x <b>E4</b> -  \"# of  used weapon slots\" x <b>E5</b>");

        javax.swing.GroupLayout formulaPanelLayout = new javax.swing.GroupLayout(formulaPanel);
        formulaPanel.setLayout(formulaPanelLayout);
        formulaPanelLayout.setHorizontalGroup(
            formulaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formulaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(formulaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(formula2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(formulaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(formula1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(formula3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        formulaPanelLayout.setVerticalGroup(
            formulaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formulaPanelLayout.createSequentialGroup()
                .addComponent(formula1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(formula3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(formula2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        paraPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Score Parameters"));

        labelE1.setFont(new java.awt.Font("Ubuntu", 0, 15));
        labelE1.setText("E1 : Defense bonus");

        labelE2.setFont(new java.awt.Font("Ubuntu", 0, 15));
        labelE2.setText("E2 : Negative skill penalty");

        labelE3.setFont(new java.awt.Font("Ubuntu", 0, 15));
        labelE3.setText("E3 : Query skill bonus");

        labelE4.setFont(new java.awt.Font("Ubuntu", 0, 15));
        labelE4.setText("E4 : Empty slot bonus");

        labelE5.setFont(new java.awt.Font("Ubuntu", 0, 15));
        labelE5.setText("E5 : Weapon slot penalty");

        menuE1.setFont(new java.awt.Font("Monospaced", 0, 12));
        menuE1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "4", "6", "8", "16", "32", "64" }));
        menuE1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuE1ActionPerformed(evt);
            }
        });

        menuE2.setFont(new java.awt.Font("Monospaced", 0, 12));
        menuE2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "10", "15", "20", "25", "30", "40" }));
        menuE2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuE2ActionPerformed(evt);
            }
        });

        menuE3.setFont(new java.awt.Font("Monospaced", 0, 12));
        menuE3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20", "30", "40", "50", "60", "70", "80" }));
        menuE3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuE3ActionPerformed(evt);
            }
        });

        menuE4.setFont(new java.awt.Font("Monospaced", 0, 12));
        menuE4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6" }));
        menuE4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuE4ActionPerformed(evt);
            }
        });

        menuE5.setFont(new java.awt.Font("Monospaced", 0, 12));
        menuE5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "3", "6", "10", "15", "20", "25" }));
        menuE5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuE5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout paraPanelLayout = new javax.swing.GroupLayout(paraPanel);
        paraPanel.setLayout(paraPanelLayout);
        paraPanelLayout.setHorizontalGroup(
            paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paraPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelE3)
                    .addComponent(labelE5)
                    .addComponent(labelE4)
                    .addComponent(labelE1)
                    .addComponent(labelE2))
                .addGap(18, 18, 18)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(menuE4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(menuE3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(menuE5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(menuE1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(menuE2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        paraPanelLayout.setVerticalGroup(
            paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paraPanelLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelE1)
                    .addComponent(menuE1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelE2)
                    .addComponent(menuE2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelE3)
                    .addComponent(menuE3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelE4)
                    .addComponent(menuE4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelE5)
                    .addComponent(menuE5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        optionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Search Options"));

        methodMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
        methodMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Full Search", "Random Search " }));
        methodMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                methodMenuActionPerformed(evt);
            }
        });

        methodMenuLabel.setFont(new java.awt.Font("Monospaced", 0, 12));
        methodMenuLabel.setText("Search Method");

        numberMenuLabel.setFont(new java.awt.Font("Monospaced", 0, 12));
        numberMenuLabel.setText("Number of Results");

        numberMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
        numberMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5", "10", "20", "40", "60", "80", "100" }));
        numberMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numberMenuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionPanelLayout = new javax.swing.GroupLayout(optionPanel);
        optionPanel.setLayout(optionPanelLayout);
        optionPanelLayout.setHorizontalGroup(
            optionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(methodMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(methodMenuLabel)
                    .addComponent(numberMenuLabel)
                    .addComponent(numberMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        optionPanelLayout.setVerticalGroup(
            optionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(methodMenuLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(methodMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(numberMenuLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(numberMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        defaultButton.setFont(new java.awt.Font("Monospaced", 0, 12));
        defaultButton.setText("Default");
        defaultButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(formulaPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(paraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(optionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(defaultButton, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(formulaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(paraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(optionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(defaultButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void defaultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultButtonActionPerformed
	 	defaultMenuSelection();
		//gen.setScoreParaDefault();
		//gen.setNumOptSetDefault();
		//gen.setOptMethodDefault();
	}//GEN-LAST:event_defaultButtonActionPerformed

	private void methodMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_methodMenuActionPerformed
		int value = methodMenu.getSelectedIndex();
		if(value < 0)return;
		gen.setOptMethod(value);
	}//GEN-LAST:event_methodMenuActionPerformed

	private void formWindowLostFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowLostFocus
		setVisible(false);
	}//GEN-LAST:event_formWindowLostFocus

	private void menuE1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuE1ActionPerformed
		String st = menuE1.getSelectedItem().toString();
		gen.setScorePara(0, Integer.parseInt(st));
	}//GEN-LAST:event_menuE1ActionPerformed

	private void menuE2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuE2ActionPerformed
		String st = menuE2.getSelectedItem().toString();
		gen.setScorePara(1, -Integer.parseInt(st));
	}//GEN-LAST:event_menuE2ActionPerformed

	private void menuE3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuE3ActionPerformed
		String st = menuE3.getSelectedItem().toString();
		gen.setScorePara(2, Integer.parseInt(st));
	}//GEN-LAST:event_menuE3ActionPerformed

	private void menuE4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuE4ActionPerformed
		String st = menuE4.getSelectedItem().toString();
		gen.setScorePara(3, Integer.parseInt(st));
	}//GEN-LAST:event_menuE4ActionPerformed

	private void menuE5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuE5ActionPerformed
		String st = menuE5.getSelectedItem().toString();
		gen.setScorePara(4, -Integer.parseInt(st));
	}//GEN-LAST:event_menuE5ActionPerformed

	private void numberMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numberMenuActionPerformed
		String st = numberMenu.getSelectedItem().toString();
		gen.setNumOptSet(Integer.parseInt(st));
	}//GEN-LAST:event_numberMenuActionPerformed

	private void defaultMenuSelection()
	{
		menuE1.setSelectedIndex(3);
		menuE2.setSelectedIndex(3);
		menuE3.setSelectedIndex(3);
		menuE4.setSelectedIndex(3);
		menuE5.setSelectedIndex(0);  // no weapon slot penalty by default
		//menuE5.setSelectedIndex(3);
		methodMenu.setSelectedIndex(0);
		numberMenu.setSelectedIndex(2);
	}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GenAdvanced dialog = new GenAdvanced(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

	private Generator gen;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton defaultButton;
    private javax.swing.JLabel formula1;
    private javax.swing.JLabel formula2;
    private javax.swing.JLabel formula3;
    private javax.swing.JPanel formulaPanel;
    private javax.swing.JLabel labelE1;
    private javax.swing.JLabel labelE2;
    private javax.swing.JLabel labelE3;
    private javax.swing.JLabel labelE4;
    private javax.swing.JLabel labelE5;
    private javax.swing.JComboBox menuE1;
    private javax.swing.JComboBox menuE2;
    private javax.swing.JComboBox menuE3;
    private javax.swing.JComboBox menuE4;
    private javax.swing.JComboBox menuE5;
    private javax.swing.JComboBox methodMenu;
    private javax.swing.JLabel methodMenuLabel;
    private javax.swing.JComboBox numberMenu;
    private javax.swing.JLabel numberMenuLabel;
    private javax.swing.JPanel optionPanel;
    private javax.swing.JPanel paraPanel;
    // End of variables declaration//GEN-END:variables

}
